package java202204;

/**
 * @Author badwei
 * @Date: 2022/4/3 17:43
 * @Description: https://leetcode-cn.com/problems/find-smallest-letter-greater-than-target/
 */

public class java03 {

    public static void main(String[] args) {
        char[] letters = {'c', 'f', 'j'};
        char target = 'a';
        //输出c
        System.out.println(nextGreatestLetter(letters,target));

    }

    /**
     * @Author badwei
     * @Date: 2022/4/3 17:13
     * @Description:
     * @param
     * @Return: {@link }
     */
    public static char nextGreatestLetter(char[] letters, char target) {


        char next = letters[0];// 如果没有比他大的就是第一个
        for (char letter : letters) {
            if ((int)letter > target){ //一旦有比他大的就break,没有就还是左边第一个
                next = letter;
                break;
            }
        }
        return next;

    }
}
